<?php if(!defined('BASEPATH')) exit('No direct script access allowed');

class Users_model extends CI_Model
{
    public function __construct() 
    { 
        parent::__construct(); 
    }
    
    public function check_user($login,$pass)
    {
        $wynik = $this->db->get_where('ut_users',array('user_login'=>$login, 'user_pass'=>$pass));
        if($wynik->num_rows()>0)
        {
            $tab['wynik']   = $wynik->row_array();
            $tab['stan']    = TRUE;
        }
        else
            $tab['stan'] = FALSE;
        return $tab;
    }
    
    public function check_rights($uid,$type,$value)
    {
        $col = 'user_'.$type;
        $wynik = $this->db->get_where('ut_users',array($col=>$value,'user_id'=>$uid));
        if($wynik->num_rows()==0)
            return TRUE;
        else
            return FALSE;
    }
    
    public function get_user($id)
    {
        $wynik = $this->db->get_where('view_users',array('user_id'=>$id));
        if($wynik->num_rows()>0)
        {
            $user = $wynik->result_array();
            foreach($user as $u)
            {
                $tab['wynik'][$u['user_id']]['name']    = $u['user_fname'].' '.$u['user_lname'];
                $tab['wynik'][$u['user_id']]['fname']   = $u['user_fname'];
                $tab['wynik'][$u['user_id']]['lname']   = $u['user_lname'];
                $tab['wynik'][$u['user_id']]['email']   = $u['user_email'];
                $tab['wynik'][$u['user_id']]['phone']   = $u['user_phone'];
                $tab['wynik'][$u['user_id']]['birth']   = $u['user_birth'];
                $tab['wynik'][$u['user_id']]['image']   = $u['user_image'];
                $tab['wynik'][$u['user_id']]['email']   = $u['user_email'];
                $tab['wynik'][$u['user_id']]['number']  = $u['pp_number'];
                $tab['wynik'][$u['user_id']]['tid']     = $u['team_id'];
                $tab['wynik'][$u['user_id']]['joined']  = $u['pt_joined'];
                $tab['wynik'][$u['user_id']]['pos'][]   = $u['pos_id'];
                $tab['wynik'][$u['user_id']]['pozycje'][$u['pos_code']]['name']     = $u['pos_name'];
                $tab['wynik'][$u['user_id']]['pozycje'][$u['pos_code']]['id']       = $u['pos_id'];
                $tab['wynik'][$u['user_id']]['pozycje'][$u['pos_code']]['active']   = $u['pp_active'];
                $tab['wynik'][$u['user_id']]['pozycje'][$u['pos_code']]['number']   = $u['pp_number'];
                $tab['wynik'][$u['user_id']]['teams'][$u['team_code']]['name']      = $u['team_name'];
                $tab['wynik'][$u['user_id']]['teams'][$u['team_code']]['logo']      = $u['team_logo'];
                $tab['wynik'][$u['user_id']]['teams'][$u['team_code']]['active']    = $u['team_active'];
                $tab['wynik'][$u['user_id']]['teams'][$u['team_code']]['joined']    = $u['pt_joined'];
                $tab['wynik'][$u['user_id']]['teams'][$u['team_code']]['left']      = $u['pt_left'];
                $tab['wynik'][$u['user_id']]['teams'][$u['team_code']]['league'][$u['league_id']]['code']   = $u['league_code'];
                $tab['wynik'][$u['user_id']]['teams'][$u['team_code']]['league'][$u['league_id']]['name']   = $u['league_name'];
                $tab['wynik'][$u['user_id']]['teams'][$u['team_code']]['comp'][$u['comp_id']]['code']       = $u['comp_code'];
                $tab['wynik'][$u['user_id']]['teams'][$u['team_code']]['comp'][$u['comp_id']]['name']       = $u['comp_name'];
                $tab['wynik'][$u['user_id']]['teams'][$u['team_code']]['city'][$u['city_id']]['code']       = $u['city_code'];
                $tab['wynik'][$u['user_id']]['teams'][$u['team_code']]['city'][$u['city_id']]['name']       = $u['city_name'];
            }
            $tab['stan']    = TRUE;
        }
        else
            $tab['stan'] = FALSE;
        return $tab;
    }
    
}